<script setup lang="ts">
import { ref, reactive } from 'vue'
import { useRoute, useRouter } from 'vue-router';
import { Session } from '@/utils/storage.ts';

const route = useRoute();
const router = useRouter();
const loginForm = reactive({
    name: '',
    password: ''
})
const formRef = ref(null);

function submitForm(param: any) {
    console.log(param);
    Session.set('token', 'admin')
    if (route.query?.redirect) {
        router.push({
            path: <string>route.query?.redirect,
            query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
        });
    } else {
        router.push('/');
    }
}

</script>

<template>
    <div>
        <el-form
            ref="formRef"
            :model="loginForm"
            label-width="120px"
            class="demo-dynamic">
            <el-form-item prop="name" label="账号">
                <el-input v-model="loginForm.name" />
            </el-form-item>
            <el-form-item prop="password" label="密码">
                <el-input v-model="loginForm.password" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm(formRef)">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>